﻿using System;
using System.Collections.Generic;
using System.Text;
using EmbeddedSharp;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.IO {

    /// <summary>
    /// filename = "c:\text.txt";
    /// write(filename, "hello, world!");
    /// </summary>
    public class WriteNode : FuncNode {

        public WriteNode()
            : base() {
            base.Value = "write";
        }

        public override object Evaluate() {
            if (Parameters.Count < 2) {
                return "usage: write(fileName, content)";
            }

            string path = Parameters[1].Evaluate().ToString();
            string content = Parameters[0].Evaluate().ToString();

            System.IO.File.WriteAllText(path, content);

            return content;
        }
    }
}
